<!DOCTYPE html>
<html>
<head>
    <title>user form</title>
    <#include "/header.html">
    <style>
        .layui-upload-img {
            max-height: 100px;
        }
    </style>
    
    <script type="text/javascript">
    function verify() {
    	var newpassword= document.getElementById("passwordnew").value;
    	if(newpassword==null||newpassword==""){
    		alert("请先输入新密码！");
    		return "";
    	}
    	var newpassword2= document.getElementById("password").value;
    	if(newpassword!=newpassword2){
    		alert("确认密码与新密码不同！");
    		return "";
    	}
		return newpassword;
    }
    </script>
</head>
<body class="bg-white">

<div id="appMain">
    <form class="layui-form layuimini-form" action="" lay-filter="dataForm">
        <div class="layui-form-item">
            <label class="layui-form-label">头像</label>
            <div class="layui-input-block">
                <input type="hidden" name="avatar" value="">
                <div class="layui-upload">
                <button type="button" class="layui-btn layui-btn-sm layui-bg-black" id="uploadBtn">选择图片</button>
                    <div class="layui-upload-list">
                        <img class="layui-upload-img" id="uploadPreview" src="${request.contextPath}/statics/images/avatar.png">
                        <p id="uploadText"></p>
                    </div>
                </div>
            </div>
        </div>
        <!-- <div class="layui-form-item">
            <label class="layui-form-label">手机号</label>
            <div class="layui-input-block">
                <input type="text" name="mobile" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">个人简介</label>
            <div class="layui-input-block">
                <input type="text" name="introduction" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">学历</label>
            <div class="layui-input-block">
                <input type="text" name="education" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">毕业学校</label>
            <div class="layui-input-block">
                <input type="text" name="graduation" class="layui-input">
            </div>
        </div> -->
        <div class="layui-form-item">
            <label class="layui-form-label">手机号</label>
            <div class="layui-input-block">
                <input type="text" name="phone" class="layui-input layui-disabled" disabled>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">邮箱</label>
            <div class="layui-input-block">
                <input type="text" name="em" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">性别</label>
            <div class="layui-input-block">
                <input type="radio" name="sex" value="1" title="男">
                <input type="radio" name="sex" value="0" title="女">
            </div>
        </div>
        <!-- <div class="layui-form-item">
            <label class="layui-form-label">状态</label>
            <div class="layui-input-block">
                <input type="radio" name="status" value="0" title="禁用">
                <input type="radio" name="status" value="1" title="启用" checked="">
            </div>
        </div> -->

        <div class="layui-form-item">
            <label class="layui-form-label required">登录密码</label>
            <div class="layui-input-block">
                <input type="password" name="passwordnew" id="passwordnew" lay-verify="required" lay-reqtext="登录密码不能为空" placeholder="输入登录密码" value="" class="layui-input" autocomplete="off">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">确认密码</label>
            <div class="layui-input-block">
                <input type="password" onblur="this.value=verify()" id="password" name="password" lay-verify="required" lay-reqtext="登录密码不能为空" placeholder="输入登录密码" value="" class="layui-input" autocomplete="off">
            </div>
        </div>
        <div class="layui-form-item layui-hide">
            <div class="layui-input-block">
                <button type="button" class="layui-btn layui-btn-normal" id="commitBtn" lay-submit lay-filter="saveBtn">确认保存</button>
            </div>
        </div>
    </form>
</div>

<script type="text/javascript">
    layui.use(['form', 'upload'], function () {
        var form = layui.form,
        	upload = layui.upload,
            $ = layui.$;
        var submitForm = function () {
            var params = form.val('dataForm');
            submitFormData('user/save', params);
        };

        //普通图片上传
        var uploadInst = upload.render({
            elem: '#uploadBtn'
            ,url: serverUrl('oss/file/upload')
            ,auto: false
            ,choose: function(obj){
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result){
                    $('#uploadPreview').attr('src', result); //base64
                });
            }
            ,done: function(res){
                if(res.code > 0){
                    return layer.msg('上传失败');
                }
                form.val('dataForm', {'avatar': res.url});
                submitForm();
            }
        });

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            var img = $('#uploadPreview').attr('src');
            if (!img) {
                layer.msg('请选择图片', {icon: 2, anim: 6});
                return false;
            }
            if (img.indexOf('data:') === 0) {
                uploadInst.upload();
                return false;
            }
            submitForm();
            return false;
        });

    });
</script>
</body>
</html>